package com.senthink.gl.business.api.controller;

import com.senthink.gl.business.common.entity.PageDto;
import com.senthink.gl.business.common.entity.SearchRequest;
import com.senthink.gl.business.common.entity.TimeSearchRequest;
import com.senthink.gl.business.device.people.PeopleRequest;
import com.senthink.gl.business.device.people.PeopleService;
import com.senthink.gl.business.response.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 民众管理Controller
 *
 * @author zooqi@senthink.com
 * @date 2017/11/28
 */
@RestController
public class PeopleController {

    @Autowired
    private PeopleService service;

    /**
     * 获取详情
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "${uri.people.people}", method = RequestMethod.GET)
    public ResponseEntity<?> getPeople(PeopleRequest request) {
        return ResponseEntity.ok(service.detail(request));
    }

    /**
     * 添加
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "${uri.people.people}", method = RequestMethod.POST)
    public ResponseEntity<?> postPeople(@RequestBody PeopleRequest request) {
        return ResponseEntity.ok(service.save(request));
    }

    /**
     * 删除
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "${uri.people.people}", method = RequestMethod.DELETE)
    public ResponseEntity<?> deletePeople(PeopleRequest request) {
        return ResponseEntity.ok(service.delete(request));
    }

    /**
     * 修改信息
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "${uri.people.people}", method = RequestMethod.PUT)
    public ResponseEntity<?> putPeople(@RequestBody PeopleRequest request) {
        return ResponseEntity.ok(service.update(request));
    }

    /**
     * 分页+筛选+搜索列表
     *
     * @param searchRequest 搜索参数
     * @param pageDTO       分页参数
     * @return
     */
    @RequestMapping(value = "${uri.people.peoples}", method = RequestMethod.GET)
    public ResponseEntity<?> peoples(SearchRequest searchRequest,
                                   @Valid PageDto pageDTO) {
        ApiResponse apiResponse = service.peopleList(searchRequest, pageDTO.convertToPageRequestOrderByTime());
        return ResponseEntity.ok(apiResponse);
    }





}
